package com.phalanxim.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.phalanxim.service.Account;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/test")
public class TestController{

	@RequestMapping(value = "/login", method = RequestMethod.GET)
  public String getLoginPage(@ModelAttribute Account account, ModelMap model)
  {
    model.addAttribute("userName", "USER NAME");
    model.addAttribute("password","PASSWORD");
    return "login";
  }

  @RequestMapping(value = "/login", method = RequestMethod.POST)
  public String login(@ModelAttribute Account account, Model model)
  {
    account.setLastVisitDate(new Date());
    return "test";
  }

  @RequestMapping(value = "/model", method = RequestMethod.GET)
  public String testModel(@ModelAttribute("model")ModelMap model)
  {
    Map<String, String> userList = new HashMap<String, String>();
    userList.put("Bill", "Gates");
    userList.put("Steve", "Jobs");
    userList.put("Larry", "Page");
    userList.put("Sergey", "Brin");
    userList.put("Larry", "Ellison");
    model.addAttribute("userList", userList);
    return "testModel";
  }

}